<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>桂房网百度地图标注页面</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.3.min.js"></script>  
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript" src="http://api.map.baidu.com/library/CityList/1.2/src/CityList_min.js"></script> 
<style>
p{padding:2px; margin:0px; font-size:12px; color:#222;}
p span{color:#bf0000;}
</style>
</head>
<body style="padding:5px; margin:0px;">
<p><b>搜索:</b>
<input id="txtarea" type="text" size="15" /> <input id="areaSearch"
type="button" value="搜索" style="cursor: pointer" /> <span>在地图上找到您的商铺位置单击标注！</span>
</p>
<div style="width: 440px; height: 300px; border: 1px solid gray; float: left;" id="container">
</div>
<div>
<p></p>
<p> <input name="txtlatitude" type="hidden" id="txtlatitude" size="25"/>
<input name="txtLongitude" type="hidden" id="txtLongitude" size="25"/>
 <input name="txtAreaCode" type="hidden" id="txtAreaCode" style="width:200px;" /> 
</p>
</div>
<script type="text/javascript">
var map = new BMap.Map("container");
<?php 
 if(!empty($point) && strlen($point)>5){
	?>
var point  = new BMap.Point(<?=$point?>);
	<?php
 }else{
?>
var point = new BMap.Point(110.305277,25.278618); 
<?php } ?>
map.centerAndZoom(point,15);

<?php if(empty($point)){ ?>
function myFun(result){
    var cityName = result.name;
    map.setCenter(cityName);
}
var myCity = new BMap.LocalCity();
myCity.get(myFun);
<?php } ?>
//IP定位获取
var marker = new BMap.Marker(point);  // 创建标注

map.addControl(new BMap.NavigationControl());
map.addControl(new BMap.ScaleControl());
 
map.addOverlay(marker);              // 将标注添加到地图中
//marker.enableDragging();    //可拖拽 
//搜索
document.getElementById("areaSearch").onclick = function () {
// 创建地址解析器实例
var myGeo = new BMap.Geocoder();
var searchTxt = document.getElementById("txtarea").value;
// 将地址解析结果显示在地图上，并调整地图视野
myGeo.getPoint(searchTxt, function (point) {
if (point) {
map.centerAndZoom(point, 16);
document.getElementById("txtlatitude").value = point.lat;
document.getElementById("txtLongitude").value = point.lng;
var pointMarker = new BMap.Point(point.lng, point.lat);
geocodeSearch(pointMarker);

map.addOverlay(new BMap.Marker(point));
}
else
alert("搜索不到结果");
}, "全国");
}
map.enableScrollWheelZoom();
 

map.addEventListener("click", function (e) {
document.getElementById("txtlatitude").value = e.point.lat;
document.getElementById("txtLongitude").value = e.point.lng;
window.opener.<?=$callback?>(e.point.lng+","+e.point.lat);
map.clearOverlays();
var pointMarker = new BMap.Point(e.point.lng, e.point.lat); // 创建标注的坐标
addMarker(pointMarker);
geocodeSearch(pointMarker);
});

function addMarker(point) {
var myIcon = new BMap.Icon("mk_icon.png", new BMap.Size(21, 25),
{ offset: new BMap.Size(21, 21),
imageOffset: new BMap.Size(0, -21)
});
var marker = new BMap.Marker(point);
map.addOverlay(marker);
}
function geocodeSearch(pt) {
var myGeo = new BMap.Geocoder();
myGeo.getLocation(pt, function (rs) {
var addComp = rs.addressComponents;
document.getElementById("txtAreaCode").value = addComp.province + ", " + addComp.city + ", " + addComp.district;
});
}
</script>
</body>
</html>